package com.xmut.bs.handaccount.adapter;

import android.content.Context;

import com.xmut.bs.handaccount.R;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Author Dollkey
 * Date 2018/4/10 15:26.
 */

public abstract class GoodsAdapter<T> extends MultiItemTypeAdapter<T> {

    private boolean typeList;

    public GoodsAdapter(Context context, List<T> datas) {
        super(context, datas);
        addItemViewDelegate(new ItemViewDelegate<T>() {
            @Override
            public int getItemViewLayoutId() {
                return R.layout.item_goods ;
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return typeList;
            }

            @Override
            public void convert(ViewHolder holder, T t, int position) {
                GoodsAdapter.this.convert(holder, t, position);
            }
        });
        addItemViewDelegate(new ItemViewDelegate<T>() {
            @Override
            public int getItemViewLayoutId() {
                return R.layout.item_goods_grid;
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return !typeList;
            }

            @Override
            public void convert(ViewHolder holder, T t, int position) {
                GoodsAdapter.this.convert(holder, t, position);
            }
        });
    }

    public GoodsAdapter<T> setTypeList(boolean typeList) {
        this.typeList = typeList;
        return this;
    }

    protected abstract void convert(ViewHolder holder, T t, int position);
}
